home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database Designers / Rational Rose 2000 / Rational Setup.EXE / common / lib / Win32 / Pipe.pm < prev    next >
Encoding:
Perl POD Document  |  1998-11-15  |  5.3 KB  |  202 lines

  1. package Win32::Pipe;
  2.  
  3. $VERSION = '0.02';
  4.  
  5. # Win32::Pipe.pm
  6. #       +==========================================================+
  7. #       |                                                          |
  8. #       |                     PIPE.PM package                      |
  9. #       |                     ---------------                      |
  10. #       |                    Release v96.05.11                     |
  11. #       |                                                          |
  12. #       |    Copyright (c) 1996 Dave Roth. All rights reserved.    |
  13. #       |   This program is free software; you can redistribute    |
  14. #       | it and/or modify it under the same terms as Perl itself. |
  15. #       |                                                          |
  16. #       +==========================================================+
  17. #
  18. #
  19. #    Use under GNU General Public License or Larry Wall's "Artistic License"
  20. #
  21. #    Check the README.TXT file that comes with this package for details about
  22. #    it's history.
  23. #
  24.  
  25. require Exporter;
  26. require DynaLoader;
  27.  
  28. @ISA= qw( Exporter DynaLoader );
  29.     # Items to export into callers namespace by default. Note: do not export
  30.     # names by default without a very good reason. Use EXPORT_OK instead.
  31.     # Do not simply export all your public functions/methods/constants.
  32. @EXPORT = qw();
  33.  
  34. $ErrorNum = 0;
  35. $ErrorText = "";
  36.  
  37. sub new
  38. {
  39.     my ($self, $Pipe);
  40.     my ($Type, $Name, $Time) = @_;
  41.  
  42.     if (! $Time){
  43.         $Time = DEFAULT_WAIT_TIME;
  44.     }
  45.     $Pipe = PipeCreate($Name, $Time);
  46.     if ($Pipe){
  47.         $self = bless {};
  48.         $self->{'Pipe'} = $Pipe;
  49.     }else{
  50.         ($ErrorNum, $ErrorText) = PipeError();
  51.         return undef;
  52.     }
  53.     $self;
  54. }
  55.  
  56. sub Write{
  57.     my($self, $Data) = @_;
  58.     $Data = PipeWrite($self->{'Pipe'}, $Data);
  59.     return $Data;
  60. }
  61.  
  62. sub Read{
  63.     my($self) = @_;
  64.     my($Data);
  65.     $Data = PipeRead($self->{'Pipe'});
  66.     return $Data;
  67. }
  68.  
  69. sub Error{
  70.     my($self) = @_;
  71.     my($MyError, $MyErrorText, $Temp);
  72.     if (! ref($self)){
  73.         undef $Temp;
  74.     }else{
  75.         $Temp = $self->{'Pipe'};
  76.     }
  77.     ($MyError, $MyErrorText) = PipeError($Temp);
  78.     return wantarray? ($MyError, $MyErrorText):"[$MyError] \"$MyErrorText\"";
  79. }
  80.  
  81.  
  82. sub Close{
  83.     my ($self) = shift;
  84.     PipeClose($self->{'Pipe'});
  85. }
  86.  
  87. sub Connect{
  88.     my ($self) = @_;
  89.     my ($Result);
  90.     $Result = PipeConnect($self->{'Pipe'});
  91.     return $Result;
  92. }
  93.  
  94. sub Disconnect{
  95.     my ($self, $iPurge) = @_;
  96.     my ($Result);
  97.     if (! $iPurge){
  98.         $iPurge = 1;
  99.     }
  100.     $Result = PipeDisconnect($self->{'Pipe'}, $iPurge);
  101.     return $Result;
  102. }
  103.  
  104. sub BufferSize{
  105.     my($self) = @_;
  106.     my($Result) =  PipeBufferSize($self->{'Pipe'});
  107.     return $Result;
  108. }
  109.  
  110. sub ResizeBuffer{
  111.     my($self, $Size) = @_;
  112.     my($Result) = PipeResizeBuffer($self->{'Pipe'}, $Size);
  113.     return $Result;
  114. }
  115.  
  116.  
  117. ####
  118. #   Auto-Kill an instance of this module
  119. ####
  120. sub DESTROY
  121. {
  122.     my ($self) = shift;
  123.     Close($self);
  124. }
  125.  
  126.  
  127. sub Credit{
  128.     my($Name, $Version, $Date, $Author, $CompileDate, $CompileTime, $Credits) = Win32::Pipe::Info();
  129.     my($Out, $iWidth);
  130.     $iWidth = 60;
  131.     $Out .=  "\n";
  132.     $Out .=  "  +". "=" x ($iWidth). "+\n";
  133.     $Out .=  "  |". Center("", $iWidth). "|\n";
  134.     $Out .=  "  |" . Center("", $iWidth). "|\n";
  135.     $Out .=  "  |". Center("$Name", $iWidth). "|\n";
  136.     $Out .=  "  |". Center("-" x length("$Name"), $iWidth). "|\n";
  137.     $Out .=  "  |". Center("", $iWidth). "|\n";
  138.  
  139.     $Out .=  "  |". Center("Version $Version ($Date)", $iWidth). "|\n";
  140.     $Out .=  "  |". Center("by $Author", $iWidth). "|\n";
  141.     $Out .=  "  |". Center("Compiled on $CompileDate at $CompileTime.", $iWidth). "|\n";
  142.     $Out .=  "  |". Center("", $iWidth). "|\n";
  143.     $Out .=  "  |". Center("Credits:", $iWidth). "|\n";
  144.     $Out .=  "  |". Center(("-" x length("Credits:")), $iWidth). "|\n";
  145.     foreach $Temp (split("\n", $Credits)){
  146.         $Out .=  "  |". Center("$Temp", $iWidth). "|\n";
  147.     }
  148.     $Out .=  "  |". Center("", $iWidth). "|\n";
  149.     $Out .=  "  +". "=" x ($iWidth). "+\n";
  150.     return $Out;
  151. }
  152.  
  153. sub Center{
  154.     local($Temp, $Width) = @_;
  155.     local($Len) = ($Width - length($Temp)) / 2;
  156.     return " " x int($Len) . $Temp . " " x (int($Len) + (($Len != int($Len))? 1:0));
  157. }
  158.  
  159. # ------------------ A U T O L O A D   F U N C T I O N ---------------------
  160.  
  161. sub AUTOLOAD {
  162.     # This AUTOLOAD is used to 'autoload' constants from the constant()
  163.     # XS function.  If a constant is not found then control is passed
  164.     # to the AUTOLOAD in AutoLoader.
  165.  
  166.     my($constname);
  167.     ($constname = $AUTOLOAD) =~ s/.*:://;
  168.     #reset $! to zero to reset any current errors.
  169.     $!=0;
  170.     $val = constant($constname, @_ ? $_[0] : 0);
  171.  
  172.     if ($! != 0) {
  173.     if ($! =~ /Invalid/) {
  174.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  175.         goto &AutoLoader::AUTOLOAD;
  176.     }
  177.     else {
  178.  
  179.             # Added by JOC 06-APR-96
  180.             # $pack = 0;
  181.         $pack = 0;
  182.         ($pack,$file,$line) = caller;
  183.             print "Your vendor has not defined Win32::Pipe macro $constname, used in $file at line $line.";
  184.     }
  185.     }
  186.     eval "sub $AUTOLOAD { $val }";
  187.     goto &$AUTOLOAD;
  188. }
  189.  
  190. bootstrap Win32::Pipe;
  191.  
  192. # Preloaded methods go here.
  193.  
  194.  
  195. # Autoload methods go after __END__, and are processed by the autosplit program.
  196.  
  197. 1;
  198. __END__
  199.  
  200.  
  201.  
  202.